package com.oa.core.task;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.oa.core.utils.SendMsgManager;
import com.oa.pm.entity.Registration;
import com.oa.pm.service.IRegistrationService;
import com.oa.system.entity.User;
import com.oa.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

@Component
public class AttendanceTask {

//    @Autowired
//    private IUserService userService;
//
//    @Autowired
//    private IRegistrationService registrationService;
//
//    @Autowired
//    private SendMsgManager sendMsgManager;

//    @Scheduled(cron = "0 0 23 * * ?")
//    public void registrationCheck(){
//        Date date = new Date();
//
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy 年 MM 月 dd 日 ");
//
//        Calendar calendar = Calendar.getInstance();
//        calendar.setTime(date);
//
//        Integer day = calendar.get(Calendar.DATE);
//        Integer hour = calendar.get(Calendar.HOUR_OF_DAY);
//        Integer minute = calendar.get(Calendar.HOUR_OF_DAY);
//
//        List<User> users = userService.selectList(new EntityWrapper<User>().eq("is_deleted", 2));
//        users.forEach(d -> {
//            Wrapper registrationWrapper = new EntityWrapper();
//            registrationWrapper.where("user_id = {0}", d.getId());
//            registrationWrapper.where("DATE_FORMAT(registration_date, '%d') = {0}", day);
//            List<Registration> checkIn = registrationService.selectList(registrationWrapper.eq("type", 1));
//            List<Registration> signOff = registrationService.selectList(registrationWrapper.eq("type", 2));
//
//
//
//            // 查看今日是否签到
//            if(checkIn == null || checkIn.size() == 0){
//                createRegistration().setType(1);
//                sendMsgManager.sendMsg(d, "新的缺卡记录", "签到-" + sdf.toString());
//                sendMsgManager.sendWeChatMsg(d, "新的缺卡记录, " + sdf.toString() + " 签到");
//                registrationService.insert(createRegistration());
//            }
//
//            // 查看今日是否签退
//            if(signOff == null || signOff.size() == 0){
//                createRegistration().setType(2);
//                sendMsgManager.sendMsg(d, "新的缺卡记录", "签退-" + sdf.toString());
//                sendMsgManager.sendWeChatMsg(d, "新的缺卡记录, " + sdf.toString() + " 签退");
//                registrationService.insert(createRegistration());
//            }
//        });
//    }
//
//    private Registration createRegistration(){
//        Registration registration = new Registration();
//        registration.setRegistrationDate(new Date());
//        registration.setAddress("");
//        registration.setStatus(5);
//        return registration;
//    }
}
